# -*- coding: utf-8 -*-
# @Time: 2025/11/9 8:53
# @Author: subencai
# @Email: 2080981057@qq.com
# @File: view01.py
# @Project: flaskProject
# @Description:
# from main import  app
# # @app.route("/")
# # def index():
# #     return "this is index"
#
#
# from flask import  render_template, request, jsonify, redirect, url_for
#
# import json
#
# # app = Flask(__name__)
# app.config['JSON_AS_ASCII'] = False
#
#
# # 响应函数（用于API交互）
# def my_response(data=None, message="success!", code=0):
#     return {
#         "code": code,
#         "message": message,
#         "data": data
#     }
#
#
# # 登录页
# @app.route("/")
# def login_page():
#     return render_template("login.html")
#
#
# # 登录处理（验证后跳转）
# @app.route("/login", methods=["POST"])
# def login():
#     if request.is_json:
#         data = request.get_json(silent=True) or {}
#         user = data.get("user")
#         passwd = data.get("passwd")
#     else:
#         user = request.form.get("user")
#         passwd = request.form.get("passwd")
#
#     # 验证成功：跳转到成功页
#     if user == "root" and passwd == "123456":
#         return redirect(url_for("success_page", user=user))  # 携带用户名跳转
#     # 验证失败：跳转到失败页
#     else:
#         return redirect(url_for("fail_page"))
#
#
# # 登录成功页
# @app.route("/success")
# def success_page():
#     user = request.args.get("user", "用户")  # 获取跳转时携带的用户名
#     return render_template("success.html", user=user)
#
#
# # 登录失败页
# @app.route("/fail")
# def fail_page():
#     return render_template("fail.html")


# router/view01.py
# from flask import Blueprint, render_template, request, redirect, url_for
#
# # 创建蓝图
# view01_bp = Blueprint("view01_bp", __name__)
#
# # 响应函数（用于API交互）
# def my_response(data=None, message="success!", code=0):
#     return {
#         "code": code,
#         "message": message,
#         "data": data
#     }
#
# # 登录页
# @view01_bp.route("/")
# def login_page():
#     return render_template("login.html")
#
# # 登录处理（验证后跳转）
# @view01_bp.route("/login", methods=["POST"])
# def login():
#     if request.is_json:
#         data = request.get_json(silent=True) or {}
#         user = data.get("user")
#         passwd = data.get("passwd")
#     else:
#         user = request.form.get("user")
#         passwd = request.form.get("passwd")
#
#     # 验证成功：跳转到成功页
#     if user == "root" and passwd == "123456":
#         return redirect(url_for("view01_bp.success_page", user=user))
#     # 验证失败：跳转到失败页
#     else:
#         return redirect(url_for("view01_bp.fail_page"))
#
# # 登录成功页
# @view01_bp.route("/success")
# def success_page():
#     user = request.args.get("user", "用户")
#     return render_template("success.html", user=user)
#
# # 登录失败页
# @view01_bp.route("/fail")
# def fail_page():
#     return render_template("fail.html")

from flask import Blueprint, render_template, request, redirect, url_for

view01_bp = Blueprint("view01", __name__)

# 登录页
# 关键修改：同时支持根路径 "/" 和 "/login" 访问登录页
@view01_bp.route("/", methods=["GET", "POST"])  # 新增根路径映射
@view01_bp.route("/login", methods=["GET", "POST"])
def login():
    if request.method == "POST":
        user = request.form.get("user")
        passwd = request.form.get("passwd")
        # 这里简单校验，实际可替换为真实逻辑
        if user == "root" and passwd == "123456":
            return redirect(url_for("view01.success"))
        else:
            return redirect(url_for("view01.fail"))
    return render_template("login.html")

# 登录成功页
@view01_bp.route("/success")
def success():
    return render_template("success.html")

# 登录失败页
@view01_bp.route("/fail")
def fail():
    return render_template("fail.html")

# 学生管理页
@view01_bp.route("/student_manage")
def student_manage():
    return render_template("student_manage.html")

# 老师管理页
@view01_bp.route("/teacher_manage")
def teacher_manage():
    return render_template("teacher_manage.html")